<?php 
use yii\helpers\Html;
 use yii\widgets\LinkPager;
 use yii\helpers\Url;
 ?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body >
   <!-- Page Layout here -->

   <div class="container_l" style="padding:3%;padding-top: 20px;background: #eeeeee">
    <!-- 第一层卡片 -->
        <div class="valign-wrapper" style="font-size: 24px">生活 <a style="margin-left: 10px;padding: 3px;font-size: 14px" class="btn" href="<?=Url::to(['admin/edit-live'])?>" >写日记</a></div>
         <form action="<?=Url::to(['admin/del'])?>" method="post">
        <table class="bordered">
      <thead >
        <tr>
          <th data-field="id">标题</th>
          <th data-field="name">作者</th>
          <th data-field="price">评论</th>
          <th data-field="price">日期</th>
          <th data-field="price">操作</th>
        </tr>
      </thead>

      <tbody>      
        <?php                
           foreach($lives as $key=>$val)
          {   
          
          $href =  Url::toRoute(['admin/modify-live','id'=>$val->id]);    
          $options1 = ['class'=>'center-align','onclick'=>'firm1(this)','live-id'=>$val->id];
          $options3 = ['href'=>$href];      
          $changeToTimestamp= strtotime($val->create_date); //将datetime格式转化为时间戳，再由时间戳转化为格式为y-m-d的datetime
          $live_time = date('Y-m-d',$changeToTimestamp);
          echo  "<tr>";
          echo "<td>"; 
           echo Html::tag('input','',['type'=>'checkbox','name'=>$val->live_title,'style'=>['position'=>'static','opacity'=>'1','pointer-events'=>'auto'],'value'=>$val->id,'class'=>'input_checkbox']);      
           echo Html::tag('a', $val->live_title,$options3);
          echo "</td>";
             echo Html::tag('td', $val->post_author_id);
             echo Html::tag('td', "0");
             echo  Html::tag('td', $live_time);
             echo "<td>";
              echo    Html::tag('a','删除',$options1);
              echo "</td>";
             echo  "</tr>";           
          }

          ?>    
          <tr>
            <td><a href="#" type="" onclick="selectAll()" class="" style="">全选</a>|<a href="#" type="" onclick="selectNone()" >取消全选</a> </td>
            <td></td>
            <td></td>
            <td><input  name="fm" value="lives" style="display: none;"></td>
            <td><input type="submit" name="" value="删除选中项"   style=""></td>
          </tr>  
      </tbody>
    </table>
      </form>
      <?= LinkPager::widget(['pagination' => $pages]); 
            ?>
       
     </div>
   

    
    
<script type="text/javascript">
   function firm1(obj) {  

        //利用对话框返回的值 （true 或者 false）  
        if (confirm("你确定提交吗？")) {  
            var id = $(obj).attr("live-id");
           var fm = "live"; 
            $.post("<?=Url::to(['admin/del'])?>",{id:id,fm:fm},function(result){
            console.log(result)});
            
        }  
        else {  
           
        }  
  
    }   
      function selectAll()
    {
        var inputs = document.getElementsByClassName("input_checkbox");
        for(var i =0;i<inputs.length;i++)
          inputs[i].checked=true;   
    } 
      function selectNone()
    {
        var inputs = document.getElementsByClassName("input_checkbox");
        for(var i =0;i<inputs.length;i++)
                 inputs[i].checked=false;        
    }      
</script>
</body>

</html>